package com.doge.walknovel.utils

import android.net.Uri
import android.os.Build
import android.text.Html
import android.text.Spanned
import androidx.core.content.FileProvider
import java.io.File


val File.uri: Uri get() = ApiCompat.getUri(this)
val String?.html: Spanned? get() = ApiCompat.fromHtml(this)

object ApiCompat {
    val fileProvider by lazy { "${appContext.packageName}.fileprovider" }
    fun getUri(file: File): Uri {
        if (Build.VERSION.SDK_INT >= 24) {
            return FileProvider.getUriForFile(
                appContext,
                fileProvider,
                file
            )
        }
        return Uri.fromFile(file)
    }

    fun fromHtml(text: String?): Spanned? {
        if (text == null) return null
        if (Build.VERSION.SDK_INT >= 24) {
            return Html.fromHtml(text, Html.FROM_HTML_MODE_COMPACT)
        }
        return Html.fromHtml(text)
    }
}

